<template>
	<div>
	</div>
</template>

<!-- 订单支付页面 -->
<script>
	import * as payApi from '@/api/payApi.js';
	import * as orderApi from '@/api/orderApi.js';
	export default {
		data() {
			return {};
		},
		onLoad({
			orderNo
		}) {
			if (orderNo) this.orderPay(orderNo);
		},
		methods: {
			// 跳转到订单列表页面
			redirectToOrderList() {
				uni.reLaunch({
					url: '/pages/order/orderList'
				});
			},
			orderPay(orderNo) {
				let that = this;
				// 微信小程序支付
				// #ifdef MP-WEIXIN
				payApi.orderPay({
					orderNo: orderNo,
					payType: 'JSAPI',
					success: res => {
						let payData = res.data;
						uni.requestPayment({
							provider: 'wxpay',
							appId: payData.appId,
							timeStamp: payData.timeStamp, // 必须是string
							nonceStr: payData.nonceStr,
							package: payData.package,
							signType: payData.signType,
							paySign: payData.paySign,
							success: e => {
								console.log('支付成功', e);
								orderApi.confirmFinishPay({
									orderNo: orderNo
								}); // 完成支付-更新订单状态
							},
							fail: err => {
								console.log('支付失败：', err);
								uni.showModal({
									content: err
								});
							},
							complete: () => {
								that.redirectToOrderList();
							}
						});
					}
				});
				// #endif
			},
		}
	};
</script>

<style></style>
